package com.djk.pojo;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@ConfigurationProperties(prefix = "audio")
@Data
@Slf4j
public class AudioType {
    private Map<String, String> mimeTypes;

    //验证文件后缀是否被支持
    public Boolean isSupportSuffix(String fileSuffix) {
        for (String key : mimeTypes.keySet()) {
            if (fileSuffix.equalsIgnoreCase(key)) {
                return true;
            }
        }
        log.info("不受支持的文件类型：{}", fileSuffix);
        return false;
    }

    public Map<String, String> getMimeTypes() {
        return mimeTypes;
    }

    public boolean isSupportType(String fileMimeType) {
        for (String key : mimeTypes.keySet()) {
            if (fileMimeType.equalsIgnoreCase(mimeTypes.get(key))) {
                log.info("校验通过的mime类型：{}", fileMimeType);
                return true;
            }
        }
        log.info("不受支持的Mime类型：{}", fileMimeType);
        return false;
    }
}
